/*
** Copyright (C) 2015-2016  Michael Roland <mi.roland@fh.hagenberg.at>
**                          FH OÖ Forschungs & Entwicklungs GmbH
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*/
package org.simalliance.openmobileapi.service.terminals.exploit;

import java.io.PrintStream;
import java.util.ArrayList;
import org.simalliance.openmobileapi.Reader;
import org.simalliance.openmobileapi.SEService;

public class OmapiInfo extends DumpableInfo {
    private final ArrayList<String> mSecureElements;
    
    public OmapiInfo(SEService service, String[] excludeSecureElements) {
        mSecureElements = new ArrayList();
        
        Reader[] readers = service.getReaders();
        for (Reader reader : readers) {
            String terminalName = reader.getName();
            mSecureElements.add(terminalName);

            if (!nameStartsWith(terminalName, excludeSecureElements)) {
            }
        }
    }
    
    private static boolean nameStartsWith(String name, String[] listOfPrefixes) {
        if ((name != null) && (listOfPrefixes != null)) {
            for (String prefix : listOfPrefixes) {
                if (name.startsWith(prefix)) {
                    return true;
                }
            }
        }
        
        return false;
    }
    
    public void dump(PrintStream out) {
        out.println("######################################################################");
        out.println("# Open Mobile API");
        out.println("######################################################################");
        out.println("Available secure elements:");
        for (String s : mSecureElements) {
            out.println("    " + s);
        }
        
        out.println("######################################################################");
        out.println();
    }
}
